#监控windows电脑的cpu占用率
import  psutil
import  requests
import  json
webhook="https://oapi.dingtalk.com/robot/send?access_token=a344c6302de67c39cec1dcaaf9d9c2d08d4811df0cd6e750e1ad14577326ad18"
#0.5秒的平均占用率
perCpu=psutil.cpu_percent(interval=0.5, percpu=False)

HEADERS = {
    "Content-Type": "application/json ;charset=utf-8 "
}
#消息体
msg={
     "msgtype": "markdown",
     "markdown": {
         "title":"服务器报警",
         "text": "#### 服务器报警 @150XXXXXXXX \n> 9度，西北风1级，空气良89，相对温度73%\n> ![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png)\n> ###### 10点20分发布 [天气](https://www.dingtalk.com) \n"
     },
      "at": {
          "atMobiles": [
              "15583162269"
          ],
          "atUserIds": [
              "user123"
          ],
          "isAtAll": "true"
      }
 }
result=requests.post(url=webhook,data=json.dumps(msg),headers=HEADERS)
print(result.text)
